#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/2/10 17:26
# @Author  : afraidbenq
# @File    : __init__.py
# @Software: PyCharm
# @Github  : github/afraidbenq
# @Email   : 329189987@qq.com
# @Desc    :
"""
总配置文件config.yaml，配置环境选择、通知等通用配置
测试服、预发布、灰度、生产环境下有各项目配置文件
test-->pre-->gray-->prod
"""
import os

from common import logger
from config.models import ConfigModel
from util.file import get_all_files
from util.file.yaml_control import GetYamlData


base_path: str = os.path.dirname(os.path.dirname((os.path.abspath(__file__))))
_data = GetYamlData(os.path.join(base_path, "config", "config.yaml")).get_yaml_data()
env = _data["env"]
_data["project"] = {}
file_list = get_all_files(os.path.join(base_path, "config", env), yaml_data_switch=True)
for file_path in file_list:
    project_name = os.path.basename(file_path).split('.')[0]
    project_info = GetYamlData(file_path).get_yaml_data()
    if project_name == "mysql" or project_name == "redis":
        _data.update(project_info)
        continue
    _data["project"][project_name] = project_info
_data.update({"base_path": base_path})
Config = ConfigModel(**_data)
for k,v in Config.dict().items():
    logger.info(f"{k}:{v}")
